﻿// using System;
// using System.Collections.Generic;
// using DL.Tools;
// using UnityEngine;
// using UnityEngine.AI;
// using UnityEngine.InputSystem;
//
// namespace DL.AI.AIBT.Example
// {
//     public class Hero : MonoBehaviour
//     {
//         private NavMeshAgent m_Agent;
//         private Animator m_Animator;
//         private BehaviourTree m_Tree;
//
//
//         [SerializeField] private GameObject m_Treasure;
//         [SerializeField] private GameObject m_Treasure2;
//         [SerializeField] private List<Transform> m_WayPoints;
//
//         [SerializeField] private bool InDanger = false;
//
//         [SerializeField] private Transform safeSpot;
//         
//         
//         private void Awake()
//         {
//             m_Agent = GetComponent<NavMeshAgent>();
//             m_Animator = GetComponent<Animator>();
//             m_Tree = new("Hero");
//             // m_Tree.AddChild(new BTLeaf("巡逻", new PatrolStrategy(transform, m_Agent, m_WayPoints)));
//
//
//             PrioritySelector actions = new PrioritySelector("Logic");
//             
//             
//             Selector gotoTreasure = new RandomSelector("gotoTreasure", 50);
//             
//             Sequence getTreasure1 = new("getTreasure1");  
//             getTreasure1.AddChild(new BTLeaf("isTreasure1?",new Condition(()=> m_Treasure.activeSelf)));
//             getTreasure1.AddChild(new BTLeaf("gotoTreasure1",
//                 new MoveTotarget(transform, m_Agent, m_Treasure.transform)));
//             gotoTreasure.AddChild(getTreasure1);
//             
//             Sequence getTreasure2 = new("getTreasure2");  
//             getTreasure2.AddChild(new BTLeaf("isTreasure2?",new Condition(()=> m_Treasure2.activeSelf)));
//             getTreasure2.AddChild(new BTLeaf("gotoTreasure2",
//                 new MoveTotarget(transform, m_Agent, m_Treasure2.transform)));
//             gotoTreasure.AddChild(getTreasure2);
//             
//             actions.AddChild(gotoTreasure);
//
//             var patrol = new BTLeaf("巡逻", new PatrolStrategy(transform, m_Agent, m_WayPoints));
//             actions.AddChild(patrol);
//             
//             
//             Sequence runtoSafety = new("runtoSafety", 100);
//
//             bool IsSafe()
//             {
//                 if (!InDanger)
//                 {
//                     runtoSafety.Reset();
//                     return false;
//                 }
//                 else
//                 {
//                     m_Tree.Reset();
//                     return true;
//                 }
//             }
//
//             runtoSafety.AddChild(new BTLeaf("IsSafe?", new Condition(IsSafe)));
//             runtoSafety.AddChild(new BTLeaf("Go to Safety", new MoveTotarget(transform,m_Agent,safeSpot)));
//             actions.AddChild(runtoSafety);
//             
//             
//             m_Tree.AddChild(actions);
//         }
//
//
//         private void Update()
//         {
//             m_Tree.Process();
//
//             if (Keyboard.current.pKey.wasPressedThisFrame)
//             {
//                 m_Tree.PrintTree();
//             }
//
//         }
//     }
// }